package com.ruoyi.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.DishFlavor;
import com.ruoyi.order.service.IDishFlavorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 菜品口味关系Controller
 * 
 * @author ruoyi
 * @date 2022-08-19
 */
@RestController
@RequestMapping("/order/flavor")
public class DishFlavorController extends BaseController
{
    @Autowired
    private IDishFlavorService dishFlavorService;

    /**
     * 查询菜品口味关系列表
     */
    @PreAuthorize("@ss.hasPermi('order:flavor:list')")
    @GetMapping("/list")
    public TableDataInfo list(DishFlavor dishFlavor)
    {
        startPage();
        List<DishFlavor> list = dishFlavorService.selectDishFlavorList(dishFlavor);
        return getDataTable(list);
    }

    /**
     * 导出菜品口味关系列表
     */
    @PreAuthorize("@ss.hasPermi('order:flavor:export')")
    @Log(title = "菜品口味关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DishFlavor dishFlavor)
    {
        List<DishFlavor> list = dishFlavorService.selectDishFlavorList(dishFlavor);
        ExcelUtil<DishFlavor> util = new ExcelUtil<DishFlavor>(DishFlavor.class);
        util.exportExcel(response, list, "菜品口味关系数据");
    }

    /**
     * 获取菜品口味关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:flavor:query')")
    @GetMapping(value = "/{dishFlavorId}")
    public AjaxResult getInfo(@PathVariable("dishFlavorId") Long dishFlavorId)
    {
        return AjaxResult.success(dishFlavorService.selectDishFlavorByDishFlavorId(dishFlavorId));
    }

    /**
     * 新增菜品口味关系
     */
    @PreAuthorize("@ss.hasPermi('order:flavor:add')")
    @Log(title = "菜品口味关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DishFlavor dishFlavor)
    {
        return toAjax(dishFlavorService.insertDishFlavor(dishFlavor));
    }

    /**
     * 修改菜品口味关系
     */
    @PreAuthorize("@ss.hasPermi('order:flavor:edit')")
    @Log(title = "菜品口味关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DishFlavor dishFlavor)
    {
        return toAjax(dishFlavorService.updateDishFlavor(dishFlavor));
    }

    /**
     * 删除菜品口味关系
     */
    @PreAuthorize("@ss.hasPermi('order:flavor:remove')")
    @Log(title = "菜品口味关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dishFlavorIds}")
    public AjaxResult remove(@PathVariable Long[] dishFlavorIds)
    {
        return toAjax(dishFlavorService.deleteDishFlavorByDishFlavorIds(dishFlavorIds));
    }


}
